<template>
  <div>
    <el-dialog
      title="编辑判断题"
      :visible.sync="editVisible"
      width="50%"
      :show-close="false"
      :close-on-click-modal="false">

      <el-form :model="editFormData" status-icon :rules="editFormData_rules" ref="editFormData" label-width="60px" class="demo-ruleForm">
        <el-row>
          <el-col :span="18">
            <el-form-item label="题目:" prop="j_title">
              <el-input type="textarea" v-model="editFormData.j_title" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="答案:" prop="ja_answer">
              <el-radio v-model="editFormData.ja_answer" label="1">√</el-radio>
              <el-radio v-model="editFormData.ja_answer" label="2">×</el-radio>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog" size="mini">取 消</el-button>
        <el-button type="primary" @click="submitData" size="mini">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  import {updateJudgment} from '@/api/questions'
  export default{
    props:["showEditVisible","editData"],
    created(){
        this.editFormData = JSON.parse(JSON.stringify(this.editData));
    },
    data(){
      return {
        editVisible:this.showEditVisible,
        editFormData:{
          j_title:"",
          ja_answer:"",
          judgmentAnswer:{
            ja_answer:""
          }
        },

        editFormData_rules:{
          j_title:[
            {required: true, message: '不能为空', trigger: 'change' }
          ],
          ja_answer:[
            {required: true, message: '不能为空', trigger: 'change' }
          ]
        }
      }
    },
    methods:{
      //关闭弹出框
      closeDialog(){
        this.addVisible = false;
        this.$emit("closeDialog","edit");
      },

      //提交
      submitData(){
        this.$refs["editFormData"].validate((valid) =>{
            if(valid){
              updateJudgment(this.editFormData).then(res=>{
                if(res.code == 200){
                  this.$message({
                    type: 'success',
                    message: '修改成功'
                  });
                  this.closeDialog();
                }else{
                  this.$message({
                    type: 'error',
                    message: '修改失败'
                  });
                }
              });
            }
        });
      }
    }
  }
</script>
